/**
 * Created by John on 2016/7/8.
 */
function dispalayWords(cursor) {
    var words = cursor.map(function (word) {
        return word.word;
    });
    var wordStr = JSON.stringify((words));
    if (wordStr.length > 33) {
        wordStr = wordStr.slice(0, 30) + '...';
    }
    print(wordStr);
}

var mongo = new Mongo("localhost");
var wordsDB = mongo.getDB("BeginningMongoDB");
wordsColl = wordsDB.getCollection("word_stats");

var cursor = wordsColl.find();
print("Total Words:", cursor.count());
print("Limiting to 10: ")
dispalayWords(cursor.limit(10));

cursor = wordsColl.find({first: 'a'});
print();
print("Total Words starting with a:", cursor.count());
print("Limiting to 3:")
dispalayWords(cursor.limit(3));

cursor = wordsColl.find({first: 'a'});
print();
print("Limiting to 5:")
dispalayWords(cursor.limit(5));